<?php

/*
 * This class is used for as Model for Product table 
 */

class Model_Memberdocument extends Model_Base {

    protected $_name = 'mem_document';
    protected $_primaryKey = 'memd_id';

    public function fetchEntryById($id) {
        $select = $this->select()
                ->from(array('lgn' => 'mem_document'))
                ->where('memd_id = ?', $id);
        // see reasoning in fetchEntries() as to why we return only an array
        $data = $this->fetchRow($select);
        if (!empty($data)) {
            return $data->toArray();
        } else {
            return array();
        }
    }

    /**
     *  This function is used to get Questions
     * @return null|Zend_Db_Table_Row_Abstract
     */
    public function fetchMemberDocuments($where = "", $limit = "", $offset = "0", $order = 'memd_id', $sort = 'ASC') {
        $select = $this->select()
                ->from(array('prtyp' => 'mem_document'));
        if ($where != '') {
            $select->where($where);
        }
        if ($limit != "") {
            $select->limit($limit, $offset);
        }
        $select->order($order . " " . $sort);
        #echo $select;exit;
        $data = parent::fetchAll($select);
        if (!empty($data)) {
            return $data->toArray();
        } else {
            return array();
        }
    }

    public function fetchMemberDocumentsByMemberId($pid = "") {

        $finalArray = Array();
        $finalArray['DOCUMENT'] = Array();

        if ($pid == "") {
            return $finalArray;
        }
        $memertImages = $this->fetchMemberDocuments("mem_id = '" . $pid . "'");
        if (count($memertImages) > 0) {
            foreach ($memertImages as $_img) {
                $finalArray['DOCUMENT'][] = $_img;
            }
        }
        return $finalArray;
    }

}
